package JDBC;

import java.sql.*;

class JDBCTest {
	public static void main(String str[]) {
		Connection con = null;
		Statement st = null;
		try {

			// 1.)Loading Driver Class
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

			// 2.)Creating the Connection
			con = DriverManager.getConnection("jdbc:odbc:jlcac2DSN", "system", "password");

			// 3.)Preparing the Query
			String qry = "insert into studentinfo values(11,'Gaurav','gaurav@yahoo.com')";

			// 4.)Creating the Statement type Object
			st = con.createStatement();

			// 5.)Submitting the Query
			int x = st.executeUpdate(qry);

			// 6.)Processing the Result
			System.out.println("Record inserted:" + x);

		} catch (ClassNotFoundException e) {
			System.out.println("Driver class notFound");
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println("Error in Database Operation");
			e.printStackTrace();
		} finally {
			// 7.)Closing the Resources
			try {
				if (st != null)
					st.close();
				if (con != null)
					con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}